!function(o){
    var b=$('body');
    function upload(){
        var id='ajax_upload'+new Date().getTime(),d = $(this);;
        b.append(`<input type="file" id="${id}" accept="${o.accept}" style="display:none">`);
        var el=$('#'+id);
        b.one('change','#'+id,function(){
            var f = new FormData();
            f.append('file',$(this)[0].files[0]);
            $.ajax({
                url: ajaxurl+o.src,
                type: 'POST',
                dataType: 'json',
                data: f,
                contentType: false,
                processData: false,
                xhr: function() {
                    var xhr = new XMLHttpRequest(),t;
                    xhr.upload.addEventListener('progress', function (e) {
                        if (e.lengthComputable) {
                            t = Math.floor(e.loaded / e.total * 100);
                            o.progress && o.progress(d, t);
                        }
                    });
                    return xhr;
                },
                success:function(r){
                    o.success(d, r);
                },
                error:function(r){
                    o.error && o.error(d,r);
                }
            });
        }),
        el.click();
    }
    b.on('click',o.click,upload);
}({
    src: 'ytecn_pjax',  //这里AppName改为你的应用ID
    click: '.ytecn_upimgbutton',
    accept: '.jpg,.jpeg,.png,.gif,.bmp,.svg',
    success: function(e, r){
        console.log('上传成功，图片链接：'+r.url);
        e.siblings('.ytecn_input_img').attr("value", r.url);
        e.siblings('img').attr('src',r.url);
        e.val('选择文件');
    },
    error: function(e){
        alert('上传失败');
    },
    progress: function(e,n){
        e.val('上传进度：'+n+'%');
    }
});